import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
  {
    name: 'home',
    path: '/',
    meta: {
      title: '首页'
    },
    redirect:'/discover',
    component: () => import('../views/Home.vue'),
    children: [
      {
        name: 'discover',
        path: '/discover',
        meta: {
          title:'发现音乐'
        },
        component:()=>import('../views/Discover.vue')
      },
      {
        name: 'recommend',
        path: '/recommend',
        meta: {
          title:'推荐音乐'
        },
        component:()=>import('../views/Recommend.vue')
      },
      {
        name: 'newmusic',
        path: '/newmusic',
        meta: {
          title:'最新音乐'
        },
        component:()=>import('../views/NewMusic.vue')
      },
      {
        name: 'userinfo',
        path: '/userinfo',
        meta: {
          title:'设置用户信息'
        },
        component:()=>import('@/views/SetUserInfo.vue')
      },
      {
        name: 'songList',
        path: '/songList',
        meta: {
          title:'歌单'
        },
        component:()=>import('@/views/SongList.vue')
      },
      {
        name: 'result',
        path: '/result',
        meta: {
          title:'搜索结果'
        },
        component:()=>import('@/views/Result.vue')
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title;
  next()
})
export default router